package cleancode.model;

import java.util.TreeSet;

/**
 * TreeSet for NameOrientedModel, model can be added with name.
 */
public class NameOrientedModelSet<T extends NameBasedModel> extends TreeSet<T>
{
    private static final long serialVersionUID = 861177027624266032L;

    public T get( String name )
    {
        for( T model : this )
        {
            if( name.equals( model.getName() ) )
            {
                return model;
            }
        }
        return null;
    }

    public boolean remove( String name )
    {
        return remove( get( name ) );
    }

    public boolean contains( String name )
    {
        return get( name ) != null;
    }

}
